<template>
    <header>
        <router-link :to="`/`"><img src="../assets/logo.png" /></router-link>
        <div class="logout" @click="logout">{{$store.state.username}}</div>
        <router-link :to="`/login`">登录</router-link>
        <router-link :to="`/register`">注册</router-link>
        <router-link :to="`/shopping`"><img class="car-icon" src="../assets/shoppingcar.svg"><span class="car-num">{{$store.state.car_num_all}}</span></img></router-link>
    </header>
</template>
<script>
export default {
    methods:{
        logout(){
            this.$store.state.username=null
            this.$store.state.shopingList=[]
            this.$store.state.car_num_all=0
            for(let i=0;i<this.$store.state.list.length;i++){
                this.$store.state.list[i].car_num=0
            }
            this.$router.push({ path: '/login' })
        }
    }
}
</script>
<style scoped>
    header{
        background-color:#eee;
        height: 50px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        width: 100%;
    }
    .logout{
        cursor: pointer;
    }
    img{
        width: 20px;
    }
    .car-icon{
        position: relative;
    }
    .car-num{
        position: absolute;
        color: #fff;
        display: inline-block;
        background: red;
        font-size: 13px;
        height: 15px;
        width:18px;
        padding-top: 3px;
        /* padding-right: 2px; */
        border-radius: 50%;
    }
</style>